package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.util.result.Result;
import com.atguigu.gmall.product.model.BaseAttrInfo;
import com.atguigu.gmall.product.model.BaseCategory1;
import com.atguigu.gmall.product.model.BaseCategory2;
import com.atguigu.gmall.product.model.BaseCategory3;
import com.atguigu.gmall.product.service.BaseAttrInfoService;
import com.atguigu.gmall.product.service.BaseCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@Api(tags = "商品接口")
@RestController
@RequestMapping("/admin/product")
public class BaseCategoryController {
    @Autowired
    private BaseCategoryService baseCategoryService;
    @Autowired
    private BaseAttrInfoService baseAttrInfoService;

    @ApiOperation("查询一级分类列表")
    @GetMapping("/getCategory1")
    public Result<List<BaseCategory1>> getCategory1(){
        List<BaseCategory1> list = baseCategoryService.getCategory1();
        return Result.ok(list);
    }

    @ApiOperation("根据一级分类id查询二级分类集合")
    @GetMapping("/getCategory2/{category1Id}")
    public Result<List<BaseCategory2>> getCategory2(@PathVariable Long category1Id){
        List<BaseCategory2> list = baseCategoryService.getCategory2(category1Id);
        return Result.ok(list);
    }

    @ApiOperation("根据二级分类id查询三级分类集合")
    @GetMapping("/getCategory3/{category2Id}")
    public Result<List<BaseCategory3>> getCategory3(@PathVariable Long category2Id){
        List<BaseCategory3> list = baseCategoryService.getCategory3(category2Id);
        return Result.ok(list);
    }

    //用户选择三级分类id，展示选择分类后得到的平台属性列表（包含平台属性值）
    @ApiOperation("根据分类Id获取平台属性集合")
    @GetMapping("/attrInfoList/{category1Id}/{category2Id}/{category3Id}")
    public Result<List<BaseAttrInfo>> attrInfoList(
            @PathVariable("category1Id") Long category1Id,
            @PathVariable("category2Id") Long category2Id,
            @PathVariable("category3Id") Long category3Id){
        List<BaseAttrInfo> list = baseAttrInfoService.attrInfoList(category1Id,category2Id,category3Id);
        return Result.ok(list);
    }

}
